home *** CD-ROM | disk | FTP | other *** search
- Path: cs.ruu.nl!usenet
- From: wsldanke@cs.ruu.nl (Wessel Dankers)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: 29 Feb 96 20:31:48 +0100
- Organization: Dept of Computer Science, Utrecht University, The Netherlands
- Message-ID: <2099.6633T1231T2431@cs.ruu.nl>
- References: <1286.6624T1439T237@cs.ruu.nl> <3Du8y*20g@yaps.rhein.de>
- <3132C4BE.2D60@cs.ruu.nl> <4h3ivp$966@hasle.sn.no>
- NNTP-Posting-Host: anx1p3.cc.ruu.nl
- X-Newsreader: THOR 2.22 (Amiga TCP/IP)
-
- Jakob Rivertz <jakob.rivertz@aftenposten.no> wrote:
- > In article <3132C4BE.2D60@cs.ruu.nl>, Wessel Dankers <wsldanke@cs.ruu.nl>
- > wrote:
- >>Arno Eigenwillig wrote:
- >>> In article <1286.6624T1439T237@cs.ruu.nl>, Wessel Dankers writes:
- >>> > Which can of course be rewritten as:
- >>> > x ^= y;
- >>> > y ^= x;
- >>> > x ^= y;
- >>> Yes.
- >>> > or if you want it real fancy:
- >>> > x ^= y ^= x ^= y;
- >>> No. Reread your C text book and find out about sequence points, side
- >>> effects, and which combinations of them are not allowed.
- >>If you would have taken a quick peek yourself you would have seen that an
- >>assignment has a return-value of itself. Anyway, I tested it and it worked.
-
- > Leave this guy alone, everyone. It's is a troll.
-
- Don't blame the guy in my .sig, he can't help it.
-
- > For those of you who have been misleaden by these posts, do get the
- > comp.lang.c-faq, read questions 4.1 through 4.6, and 6.1 (which discusses
- > this very example). You are not allowed to modify the same value twice
- > between sequence points. Sequence points are implied by `&&', `||', `,',
- > `? :' and `;'. For example:
-
- > <never use these>
- > a[i] = i++;
- > j = i++ * i++;
- > x ^= y ^= x ^= y;
- > i = ++i;
- > </never use these>
-
- I.e. you can't assume anything about the order in which a statement is
- evaluated. So, if I write:
- printf("%d", time(NULL));
- my compiler could very well first print the time and then ask the system what
- time it is. Interesting thought. So, if I have the right compiler I can
- compute PI in 1,000,000,000,000 decimals in 0 seconds, and then sneekily
- switch off the computer when it's about to actually calculate PI. Hmmm..
-
- Well, if it's in the FAQ it must be true...
-
- --
- Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- ///|\\\
- ----------------------------oOO--(_)---OOo----------------------------
- `Never imagine yourself not to be otherwise than what it might appear
- to others that what you were or might have been was not otherwise than
- what you had been would have appeared to them to be otherwise.'
-
-